<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>向服务器传递json数据</title>
    <script src="js/jquery-1.12.4.min.js"></script>
    <script type="text/javascript">
        $('#but_json_json').click(function(){
            var j ={"name":"王","password":123456};//json对象

            $.ajax(
                {
                    url:"servlet/JsonObject", //访问路径
                    type:"POST",    //访问方式
                    data:j, //传入服务端的数据
                    dataType:"json",
                    contentType:"application/json;charset=utf-8",
                    success : function(data){
                        alert(data);
                        alert(data.name);


                        alert(data.password);
                    }

                }
            );
        });
    </script>
</head>
<body>

</body>
</html>